package com.wfm.mianshi;

public class Demo3 {
    // 1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9
    public static int getKthNum(int n,int k){
        int now = 1;
        k--;
        while(k>0){
           int step = countStep(now,now+1,n) ;
           if(step<=k){
               now++;
               k=k-step;
           }else {
               now*=10;
               k--;
           }
        }
        return now;
    }
    // 1 10 11 12  10 12 ->2
    // 1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9
    public static int countStep(int cur,int next,int n){
        int step = 0;
        while (cur<=n){
            step+=Math.min(n+1,next)-cur;
            cur*=10;
            next*=10;
        }
        return step;
    }

    public static void main(String[] args) {
//        int n = 20;
//        int k = 5;
//        System.out.println(getKthNum(n,k));
        System.out.println(countStep(1,19,200));
    }
}
